﻿using OnlineAuction.Business;
using OnlineAuction.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace OnlineAuction.Users
{
    public partial class ItemsDisabled : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Cookies["UserInfo"] == null)
            {
                Response.Redirect("../Home.aspx");
            }
            else if (!Page.IsPostBack)
            {
                GetItemsDisabled();
            }
        }

        private void GetItemsDisabled()
        {
            //Get all item selling by user logged in
            ItemBO bo = new ItemBO();
            List<ItemsE> list = bo.ItemsDisabled(Request.Cookies["UserInfo"]["UserName"].ToString());
            cpItemsDisabled.PageSize = 10;
            cpItemsDisabled.ShowFirstLast = true;
            cpItemsDisabled.DataSource = list;
            cpItemsDisabled.BindToControl = grvItems;
            grvItems.DataSource = cpItemsDisabled.DataSourcePaged;
        }

        protected void grvItems_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName.CompareTo("Delete") == 0)
            {
                ItemBO bo = new ItemBO();
                if (bo.DeleteItem(e.CommandArgument.ToString()))
                {
                    Response.Redirect(Request.RawUrl);
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this, GetType(), "alertmsg",
                    "alert('Fail to delete...!!!');", true);
                }
            }
        }

        protected void grvItems_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {

        }
    }
}